import school30.*;
import school30.ui.*;

class Tetris extends School30App {
    public Object lock = new Object();
    public boolean destroying = false;

    public Color[] colors = {
            new Color((byte)255, (byte)0, (byte)0, (byte)0),
            new Color((byte)0,  (byte)255, (byte)0, (byte)0)
    };

    private int xOrg=getWidth()/2-5;
    private int yOrg=getHeight()/2-5;

    public Tetris() {
        destroying = false;
    }

    public void startApp() {
        int i = 0;
        synchronized (lock) {
            while (!destroying) {
                paintRect(colors[i]);
                try {
                    lock.wait(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i = 1 - i;
            }
        }
    }

    private void paintRect(Color color) {
        for(int i=0; i != 10; i++) {
            for(int j=0; j != 10; j++) {
               getSprite()[i+xOrg][i+yOrg] = color;
            }
        }
    }

    public void terminateApp() {
        synchronized (lock) {
            destroying = true;
            lock.notify();
        }
    }

   public void keyPressed(int kc) {
     // do nothing
   }

   public void keyReleased(int kc) {
     // do nothing
   }


}
